//
//  KSTopTipItem.swift
//  ANOASTORE
//
//  Created by hudan on 2025/9/15.
//  Copyright © 2025 zwb. All rights reserved.
//

import UIKit

class KSTopTipItem: UIView {
        
    var title: String? {
        didSet {
            if let title = title {
                titleLab.text = title
            }
        }
    }
    
    var text: String? {
        didSet {
            if let text = text {
                let style = NSMutableParagraphStyle()
                style.lineSpacing = 6
                style.alignment = .left
                style.firstLineHeadIndent = 30
                
                let attrStr = NSMutableAttributedString.init(string: text, attributes: [.paragraphStyle: style])
                textLab.attributedText = attrStr
                
                let height = textLab.sizeThatFits(CGSize(width: ks_width, height: CGFloat.greatestFiniteMagnitude)).height
                ks_height = 10 + 20 + 6 + height + 10
            }
        }
    }
    
    private let titleLab = UILabel().easy(.systemGray, .systemFont(ofSize: 14))
    
    private let textLab = UILabel().easy(.systemGray, .systemFont(ofSize: 14))
        .extNumberOfLines(lines: 0)
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func initUI() {
        
        addSubview(titleLab)
        titleLab.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.height.equalTo(20)
        }
        
        addSubview(textLab)
        textLab.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10)
            make.top.equalTo(titleLab.snp.bottom).offset(6)
        }
    }
    
    
}
